using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LocalDemoPlayerCtl : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        if (h != 0)
        {
            h = h > 0 ? 1 : -1;
        }

        if (v != 0)
        {
            v = v > 0 ? 1 : -1;
        }

        if (h != 0)
        {
            v = 0;
        }

        Vector2 dir = new Vector2(h, v).normalized;
        LocalDemoPlayer localDemoPlayer = LDPlayerManager.getInstance().localPlayer;
        if (dir != localDemoPlayer.dir)
        {
            Debug.Log(dir.x+":"+dir.y);
            localDemoPlayer.dir = dir;
            MoveMsg msg = new MoveMsg();
            msg.position = new Vector2();
            msg.position.x = localDemoPlayer.obj.transform.position.x;
            msg.position.y = localDemoPlayer.obj.transform.position.y;
            msg.velocity = dir;
            LDPlayerManager.getInstance().sendServerMsg(msg);
        }
    }
}
